package com.zhang.hadoop.netty.nio.buffer;

import java.nio.IntBuffer;

/**
 * @author: zhang yufei
 * @create: 2022-01-08 17:39
 **/
public class TestBuffer {

    public static void main(String[] args) {
        IntBuffer intBuffer = IntBuffer.allocate(5);
        for (int i = 0; i < intBuffer.capacity(); i++) {
            intBuffer.put(i * 2);
        }
        //intBuffer转换，读写切换
        intBuffer.flip();

        while (intBuffer.hasRemaining()) {
            System.out.println(intBuffer.get());
        }

        System.out.println("重新设置索引位置");
        //设置索引位置
        intBuffer.position(1);
        while (intBuffer.hasRemaining()) {
            System.out.println(intBuffer.get());
        }
    }
}
